class PipTools < Formula
  include Language::Python::Virtualenv

  desc "Locking and sync for Pip requirements files"
  homepage "https://pip-tools.readthedocs.io"
  url "https://files.pythonhosted.org/packages/fd/01/f0055058a86a888f32ac794fa68d5a25c2d2f7a3e8181474b711faaa2145/pip-tools-7.3.0.tar.gz"
  sha256 "8e9c99127fe024c025b46a0b2d15c7bd47f18f33226cf7330d35493663fc1d1d"
  license "BSD-3-Clause"
  revision 1

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_sonoma:   "4052f4bc2689e59c10cace85bad396de0c085f91941dcab19b47319c0d2fcfde"
    sha256 cellar: :any_skip_relocation, arm64_ventura:  "736336df91c8be6e5b920bf3b1e458f5d46ea47533edf12e374fb5f7dedb45cd"
    sha256 cellar: :any_skip_relocation, arm64_monterey: "9bb03f6c7adf0ca8b72393b6961487b6313f1e0fcda01561b2efff000eef56a2"
    sha256 cellar: :any_skip_relocation, sonoma:         "a285cdcbeb76a33db70469597a06f7fcee50750d3e0e509e571440e80d63c061"
    sha256 cellar: :any_skip_relocation, ventura:        "baaec6000a5a3147c93458c500865cd27de9e4bbeaeb2b796c477a001c47fac6"
    sha256 cellar: :any_skip_relocation, monterey:       "f50929354a6f87d1b878c83ac8218fa1bb06dda7e8806e391648496bae9a8e28"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "6d244733cd96122231975a6ff9c73402c5f6de524dbd3d506bd55dd58b398cbd"
  end

  depends_on "python-build"
  depends_on "python-click"
  depends_on "python-packaging"
  depends_on "python-pyproject-hooks"
  depends_on "python@3.12"

  resource "setuptools" do
    url "https://files.pythonhosted.org/packages/fc/c9/b146ca195403e0182a374e0ea4dbc69136bad3cd55bc293df496d625d0f7/setuptools-69.0.3.tar.gz"
    sha256 "be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78"
  end

  resource "wheel" do
    url "https://files.pythonhosted.org/packages/b0/b4/bc2baae3970c282fae6c2cb8e0f179923dceb7eaffb0e76170628f9af97b/wheel-0.42.0.tar.gz"
    sha256 "c45be39f7882c9d34243236f2d63cbd58039e360f85d0913425fbd7ceea617a8"
  end

  def install
    virtualenv_install_with_resources

    %w[pip-compile pip-sync].each do |script|
      generate_completions_from_executable(bin/script, shells: [:fish, :zsh], shell_parameter_format: :click)
    end
  end

  test do
    (testpath/"requirements.in").write <<~EOS
      pip-tools
      typing-extensions
    EOS

    compiled = shell_output("#{bin}/pip-compile requirements.in -q -o -")
    assert_match "This file is autogenerated by pip-compile", compiled
    assert_match "# via pip-tools", compiled
  end
end
